// pages/message/detail.js
const mixins = require('../../../mixins/message');
var a, e, app = getApp();
const common = require('../../../mixins/common')
const options = {

  /**
   * 页面的初始数据
   */
  data: {
    currentConfig: {
      show: false,
      transition: true,
      zIndex: 99,
      locked: false,
      direction: 'bottom',
      arcRadius: 18,
      maxHeight: 600,
      minHeight: 600,
      opacity: 0.4
    },
    emojiShow: false,
    emojiChars: ["😀", "😁", "😂", "😃", "😄", "😅", "😆", "😉", "😊", "😋", "😎", "😍", "😘", "😗", "😙", "😚", "☺", "😇", "😐", "😑", "😶", "😏", "😣", "😥", "😮", "😯", "😪", "😫", "😴", "😌", "😛", "😜", "😝", "😒", "😓", "😔", "😕", "😲", "😷", "😖", "😞", "😟", "😤", "😢", "😭", "😦", "😧", "😨", "😬", "😰", "😱", "😳", "😵", "😡", "😠", "👦", "👧", "👨", "👩", "👴", "👵", "👶", "👱", "👮", "👲", "👳", "👷", "👸", "💂", "🎅", "👰", "👼", "💆", "💇", "🙍", "🙎", "🙅", "🙆", "💁", "🙋", "🙇", "🙌", "🙏", "👤", "👥", "🚶", "🏃", "👯", "💃", "👫", "👬", "👭", "💏", "💑", "👪", "💪", "👈", "👉", "☝", "👆", "👇", "✌", "✋", "👌", "👍", "👎", "✊", "👊", "👋", "👏", "👐", "✍", "👣", "👀", "👂", "👃", "👅", "👄", "💋", "👓", "👔", "👕", "👖", "👗", "👘", "👙", "👚", "👛", "👜", "👝", "🎒", "💼", "👞", "👟", "👠", "👡", "👢", "👑", "👒", "🎩", "🎓", "💄", "💅", "💍", "🌂"],
    content: "",
    keyboardHeight: 400,
    page:1,
    messageList:[],

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    this.setData({
      receive: options.userid,
      type: options.type,
      name: options.name,
    })
    this.getPrivatemessage({
      receive: options.userid,
      page: this.data.page
    })

  },

  onInputChange: function (t) {
    var e = t.detail.value;
    this.setData({
      content: e
    });
  },

  onInputFocus: function (t) {
    console.log("chat-edit-view => 输入框获取焦点"), console.log(t), this.data.emojiShow = !1;
    var e = wx.getSystemInfoSync(),
      a = parseInt(750 * t.detail.height / e.windowWidth);
    a > 0 && this.data.keyboardHeight != a && (this.data.keyboardHeight = a);
  },

  onEmojiText: function (t) {
    var e = t.currentTarget.dataset.index;
    this.data.content = this.data.content + this.data.emojiChars[e], this.setData({
      content: this.data.content
    });
  },

  onEmojiClick: function () {
    this.data.emojiShow ? this.setData({
      emojiShow: !1
    }) : this.setData({
      emojiShow: !0,
      keyboardHeight: this.data.keyboardHeight
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let user = app.globalData.user
    if (!user) {
      wx.showToast({
        title: '未登录,请登录',
      })
      wx.navigateTo({
        url: '/pages/login/login',
      })
    }
    this.setData({
      user: user,
    })
  },


  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.setData({
      reply: '',
      content: '',
      messageList:[],
      page:1,
      emojiShow: false,
    })
    that.getPrivatemessage({
      page:that.data.page,
      receive: this.data.receive,
    })
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if(!this.data.isLastPage){
      this.getPrivatemessage({
        receive: this.data.receive,
        page: this.data.page
      })
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
}
mixins(options)
common(options)
Page(options)